﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeSample.Model
{
    public class SampleMan : IComparer<SampleMan>, IEquatable<SampleMan>
    {
        private string id;
        private string name;
        private SampleDescription description;
        private string code;

        public string Id
        {
            get { return id; }
            set { id = value; }
        }
        private string language;

        public string Language
        {
            get { return language; }
            set { language = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public SampleDescription Description
        {
            get { return description; }
            set { description = value; }
        }

        public string Code
        {
            get { return code; }
            set { code = value; }
        }

        public SampleMan() { }

        public SampleMan(string language, string name, string code, SampleDescription description)
        {
            this.language = language;
            this.name = name;
            this.code = code;
            this.description = description;
        }

        public SampleMan(string id, string language, string name, string code, SampleDescription description)
        {
            this.id = id;
            this.language = language;
            this.name = name;
            this.code = code;
            this.description = description;
        }

        public bool isNameContains(string UpperCasekeyword)
        {
            if (this.name.ToUpper().Contains(UpperCasekeyword))
                return true;
            else
                return false;
        }

        public bool isDescriptionContains(string UpperCasekeyword)
        {
            if (this.description.Purpose.ToUpper().Contains(UpperCasekeyword) ||
                this.description.Author.ToUpper().Contains(UpperCasekeyword))
                return true;
            else
                return false;
        }

        public int Compare(SampleMan x, SampleMan y)
        {
            return x.name.CompareTo(y.name);
        }

        public bool Equals(SampleMan other)
        {
            if (!this.Language.Trim().ToUpper().Equals(other.Language.Trim().ToUpper()))
                return false;

            if (!this.Name.Trim().ToUpper().Equals(other.Name.Trim().ToUpper()))
                return false;

            if (!this.Code.Trim().ToUpper().Equals(other.Code.Trim().ToUpper()))
                return false;

            if (!this.Description.Equals(other.Description))
                return false;

            return true;
        }

        public bool IsIDTheSame(SampleMan other)
        {
            return this.id.ToUpper().Equals(other.id.ToUpper());
        }
    }
}
